#!/usr/bin/env python
# -*- coding: utf-8 -*-
#############################
#
# @fileName task.py
# @email:peterliuzy@gmail.com
# @author peter
#
#############################
import sys,urllib,re,md5,os,zlib,time
import MySQLdb
import ConfigParser
#ROOT_PATH = os.path.dirname(__file__)
#sys.path.append("../common")
#import crc32
#exit()
class userToImg:
    def __init__(self):
        self.db = MySQLdb.connect(user='root', db='51shanku', passwd='root', host='localhost')
    
    def up(self,u,p):
        for i in u:
            id = i[0]
            sql = "update user_info set is_process=%d where id=%d " % (p,id)
            cursor = self.db.cursor()
            cursor.execute(sql)
    
    def run(self):
        while True:
            getUSql = "select * from user_info where is_process=0 limit 20"
            cursor = self.db.cursor()
            cursor.execute(getUSql)
            info = cursor.fetchall()
            self.up(info,2)
            if len(info) < 1:
                break
            for i in info:
                cursor = self.db.cursor()
                space = i[13].replace("u/","")
                id = str(i[0])
                crcKey = str(zlib.adler32(str(time.time()) + "_" +id))
                p_sql = "update photo set uid="+id+",u_crc_key="+crcKey+" where root like '"+space+"/show/%'"
                sql = "update user_info set is_process=2,crc_key=%s where id=%s " % (crcKey,id)
                cursor.execute(p_sql)
                cursor.execute(sql)
                print "当前:%s  -> %s" % (id,crcKey)

if __name__ == "__main__":
    u = userToImg()
    u.run()